<template>
  <div class="components-container" v-cloak>
    <sweet-modal ref="dialog" class="dialog" :sweetModalMaxWidth="pageWidth">
      <h3>{{title}}</h3>
      <div style="margin:10px 20px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="chd.REGBUSNUM" placeholder="请输入业务编号">
              <el-button slot="append" icon="el-icon-search" @click="getChdData" v-if="isAdd"></el-button>
              </el-input>
            </div>
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="chd.REGNAME" readonly>
                <el-button slot="append" @click="OpenChdDialog" v-if="isAdd">搜</el-button>
              </el-input>
            </div>
            <label class="layui-form-label">客户姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="chd.REGBUYNAME"></el-input>
            </div>
            
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">减免类型</label>
            <div class="layui-input-inline">
              <el-input v-model="chd.REGISKEYPOINTDESC" readonly></el-input>
            </div>
            <label class="layui-form-label">接尸地点</label>
            <div class="layui-input-inline">
              <el-input v-model="chd.REGADDRESS" style="width:465px;" readonly></el-input>
            </div>
          </div>
        </div>
      </div>
      <div :style="{maxHeight:maxHeight+'px'}" style="overflow:auto;">
        <table class="layui-table" style="border-spacing: 0;">
          <colgroup>
            <col>
            <col width="150">
            <col width="150">
            <col>
            <col>
            <col width="150">
            <col>
            <col>
          </colgroup>
          <thead>
            <tr>
              <th>项目名称</th>
              <th>单价</th>
              <th>数量</th>
              <th>应收金额</th>
              <th>减免金额</th>
              <th v-if="!isHidden">优惠金额</th>
              <th>应缴金额</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody ref='inputs'>
            <tr class="allRow" v-for="(chl,index) in chlList">
              <td>
                <el-select @change="chaSelect(index)" ref="select" v-model="chl.CHLCHAID" clearable @keydown.enter.native="enterEvent(index,0)"
                  :filter-method="chaFilter" @visible-change="reset()" filterable>
                  <el-option v-for="item in chaList" :key="item.CHAID" :label="item.CHANAME" :value="item.CHAID" v-show="!disabled(item.CHAID)">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-input @keyup.native="check(index)" @keydown.enter.native="enterEvent(index,1)" v-model="chl.CHLMONEY">
                  <template slot="append">元</template>
                </el-input>
              </td>
              <td>
                <el-input @keyup.native="check(index)" @keydown.enter.native="enterEvent(index,2)" v-model="chl.CHLNUM">
                  <template v-if="chl.CHLAUNIT" slot="append">{{chl.CHLAUNIT}}</template>
                </el-input>
              </td>
              <td>
                {{chl.CHLMOUNT}}元
              </td>
              <td>
                {{chl.CHLREDUCTION}}元
              </td>
              <td v-if="!isHidden">
                <el-input @keyup.native="check(index)" @keydown.enter.native="enterEvent(index,3)" v-model="chl.CHLDISCOUNT">
                  <template slot="append">元</template>
                </el-input>
              </td>
              <td>
                {{chl.CHLRECEIVED}}元
              </td>
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" @click="remove(index)">
                   <i class="layui-icon">&#xe640;</i>
                 </button>
              </td>

            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="2">
                <el-button v-if="isCommon()" type="primary" @click="getCommonItem">添加常用项</el-button>
              </td>
              <td>
                <span>合计</span>
              </td>
              <td>{{ mountTotal }}元</td>
              <td>{{ reductionTotal }}元</td>
              <td v-if="!isHidden">{{ discountTotal }}元</td>
              <td>{{ chlreceivedTotal }}元</td>
              <td>
                <button class="layui-btn layui-btn-small layui-btn-normal" v-if="isHasChd" @click="insert()">
                  <i class="layui-icon">&#xe654;</i>
                </button>
              </td>
            </tr>
          </tfoot>
        </table>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" :loading="this.$store.state.isloading" @click="submit()">保存</el-button>
      </div>
    </sweet-modal>
    <sweet-modal ref="info" class="dialog" :sweetModalMaxWidth="pageWidth">
      <h3>{{title}}</h3>
      <div style="margin:10px 20px">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="chd.REGBUSNUM"  readonly>
              </el-input>
            </div>
            <label class="layui-form-label">逝者姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="chd.REGNAME"></el-input>
            </div>
            <label class="layui-form-label">客户姓名</label>
            <div class="layui-input-inline">
              <el-input v-model="chd.REGBUYNAME"></el-input>
            </div>

          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">减免类型</label>
            <div class="layui-input-inline">
              <el-input v-model="chd.REGISKEYPOINTDESC" readonly></el-input>
            </div>
            <label class="layui-form-label">接尸地点</label>
            <div class="layui-input-inline">
              <el-input v-model="chd.REGADDRESS" style="width:465px;" readonly></el-input>
            </div>
          </div>
        </div>
      </div>
      <div style="maxHeight:500px;overflow:auto;">
        <table class="layui-table" lay-even>
          <colgroup>
            <col>
            <col>
            <col>
            <col>
            <col>
            <col>
            <col>
          </colgroup>
          <thead>
            <tr>
              <th>项目名称</th>
              <th>单价</th>
              <th>数量</th>
              <th>应收金额</th>
              <th>减免金额</th>
              <th v-if="!isHidden">优惠金额</th>
              <th v-if="chdData.CHDSTATUS==='B'">实收金额</th>
              <th v-else="chdData.CHDSTATUS==='B'">应缴金额</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(chl,index) in chlList">
              <td>{{chl.CHLCHANAME}}</td>
              <td>{{chl.CHLMONEY}}元</td>
              <td>{{chl.CHLNUM}}{{chl.CHLAUNIT}}</td>
              <td>{{chl.CHLMOUNT}}元</td>
              <td>{{chl.CHLREDUCTION}}元</td>
              <td v-if="!isHidden">{{chl.CHLDISCOUNT}}元</td>
              <td>{{chl.CHLRECEIVED}}元</td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="3">合计</td>
              <td>{{ mountTotal }}元</td>
              <td>{{ reductionTotal }}元</td>
              <td v-if="!isHidden">{{ discountTotal }}元</td>
              <td>{{ chlreceivedTotal }}元</td>
            </tr>
          </tfoot>
        </table>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button @click="closeDialog">取消</el-button>
      </div>
    </sweet-modal>
    <el-dialog title="收费信息" ref="chddialog" :visible.sync="dialogTableVisible">
      <el-table :data="chdData" max-height="600">
        <el-table-column property="REGNAME" label="逝者姓名" width="150"></el-table-column>
        <el-table-column property="REGBUYNAME" label="客户姓名" width="200"></el-table-column>
        <el-table-column property="REGADDRESS" label="地址"></el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
      <template slot-scope="scope">
        <el-button @click="selectClick(scope.row)" type="text" size="small">选择</el-button>
      </template>
    </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>


<script>
  import sweetModal from "@/components/sweetModal";
  import apiBase from "@/api/apiBase.js";
  import {
    accMul,
    Subtr,
    accAdd
  } from "@/utils/operations.js";
  import {
    ORDER
  } from "@/const/orderConst.js";

  const MANUAL = "A";
  const AUTO = "B";

  export default {
    name: "hello",
    data() {
      return {
        isAdd:false,
        isHasChd:false,
        dialogTableVisible:false,
        pageWidth: 1200,
        maxHeight: 500,
        COTID: null,
        order: null,
        title: null,
        //所有收费项目
        allCharge: [],
        chaList: [],
        pointType: [],
        isHidden: null,
        //收费信息
        chdData: [{}],
        //选择的收费信息
        chd:{
            CHDID:null,
            REGBUSNUM:null,
            REGNAME:null,
            REGBUYNAME:null,
            REGADDRESS:null,
            REGISKEYPOINT:null,
            REGISKEYPOINTDESC:null,
        },
        //收费项目
        chlList: [],
        chl: {
          CHLCHAID: "", //收费项目ID（必传）
          CHLCHANAME: "", //收费项目名称（必传）
          CHLMOUNT: 0, //应缴金额（必传）
          CHLPRICE: null, //起步价
          CHLHIPRICE: null, //最高价
          CHLMONEY: 0, //单价
          CHLNUM: 1, //数量
          CHLAUNIT: null, //计量单位
          CHLREDUCTION: 0, //减免金额
          CHLDISCOUNT: 0, //优惠金额
          CHLDESC: null, //备注
          CHLRECEIVED: 0,
          CHLFROMLOGO: MANUAL //来源标记
        }
      };
    },
    methods: {
              //个性化
      getParam() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Param.GetIsHidePreferential,
          res => {
            this.isHidden = res.data.content;
          }
        );
      },
        OpenChdDialog()
        {
            this.getUnCheckData();
            this.dialogTableVisible=true;
        },
        getChdData()
        {
          if(!this.chd.REGBUSNUM)
          {
            this.$message({
            type: "error",
            message: "请填写业务编号后再查询!"
          });
          return;
          }
          let data = {REGBUSNUM:this.chd.REGBUSNUM};
          apiBase.DoService(
            data,
            apiBase.getApiAdress().Cost.GetUnCheckChd,
            res => {
              let cotdate = res.data.content;
              this.chd.CHDID=cotdate.CHDID;
              this.chd.REGID = cotdate.REGID;
              this.chd.REGNAME = cotdate.REGNAME;
              this.chd.REGBUYNAME = cotdate.REGBUYNAME;
              this.chd.REGADDRESS=cotdate.REGADDRESS;
              this.chd.REGISKEYPOINT=cotdate.REGISKEYPOINT;
              this.chd.REGISKEYPOINTDESC=cotdate.REGISKEYPOINTDESC;
              if(!this.chd.CHDID)
              {
                 this.$message({
                  type: "error",
                  message: "业务已结账或不存在!"
                });
                return;
              }
              this.isHasChd=true;
              this.chlList=[];
              this.getAllCharge(this.chd.REGISKEYPOINT);
              this.insert();
          } 
        );     
        },
        selectClick(row)
        {
            if(row)
            {
             this.chd.CHDID=row.CHDID;
             this.chd.REGID=row.REGID;
             this.chd.REGNAME=row.REGNAME;
             this.chd.REGBUSNUM=row.REGBUSNUM;
             this.chd.REGBUYNAME=row.REGBUYNAME;
             this.chd.REGADDRESS=row.REGADDRESS;
             this.chd.REGISKEYPOINT=row.REGISKEYPOINT;
             this.chd.REGISKEYPOINTDESC=row.REGISKEYPOINTDESC;
            }
            this.dialogTableVisible=false;
            this.isHasChd=true;
            this.chlList=[];
            this.getAllCharge(this.chd.REGISKEYPOINT);
            this.insert();


        },
      //获取未结账信息
      getUnCheckData() {
        let data = {};
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Cost.QueryUnCheckChd,
          res => {
            this.chdData=res.data.content;
          }
        );
      },
      //收费项目
      getAllCharge(skeyPoint) {
        let data = {
          Data: {
            REGISKEYPOINT: skeyPoint
          }
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Checkout.GetAllCharge,
          res => {
            this.allCharge = res.data.content.OutData;
            this.chaList = JSON.parse(JSON.stringify(this.allCharge));
            for (var index in this.chlList) {
              this.chlCompute(index);
            }
          }
        );
      },
      //收费详情
      dataInfo() {
        let data = {
          COTID: this.COTID
        };
        apiBase.DoService(data, apiBase.getApiAdress().Cost.Detail, res => {
          let cotdate = res.data.content;
          this.chd.CHDID=cotdate.COTCHDID;
          this.chd.REGID = cotdate.COTREGID;
          this.chd.REGNAME = cotdate.REGNAME;
          this.chd.REGBUSNUM = cotdate.REGBUSNUM;
          this.chd.REGBUYNAME = cotdate.COTBUYNAME;
          this.chd.REGADDRESS=cotdate.REGADDRESS;
          this.chd.REGISKEYPOINT=cotdate.REGISKEYPOINT;
          this.chd.REGISKEYPOINTDESC=cotdate.REGISKEYPOINTDESC;
          this.chlList = cotdate.List_Chl;  
          for (let chl of this.chlList) {
            if (!this.chaList.some(item => {
                return item.CHAID === chl.CHLCHAID;
              }))
              this.chaList.push({
                CHANAME: chl.CHLCHANAME,
                CHAID: chl.CHLCHAID
              });
          }
          this.isHasChd=true;
        });
      },
      //修改收费项目
      dataModify() {
        let chlList = JSON.parse(JSON.stringify(this.chlList));
        console.log("chlList", chlList);
        chlList = chlList.filter(item => {
          return item.CHLCHAID && item.CHLCHAID.length > 0;
        });
        let data = {
          COTID: this.COTID,
          COTCHDID:this.chd.CHDID,
          COTREGID:this.chd.REGID,
          COTBUYNAME:this.chd.REGBUYNAME,
          List_Chl:chlList
        };
        if (chlList.length > 0) {
          data.List_Chl = chlList;
        }
        apiBase.DoService(data, apiBase.getApiAdress().Cost.Modify, res => {
          this.$message({
            type: "success",
            message: "保存成功!"
          });
          this.closeDialog();
          this.refreshData();
        });
      },
      //新增
      dataAdd() {
        let chlList = JSON.parse(JSON.stringify(this.chlList));
        console.log(JSON.stringify(this.chlList));
        chlList = chlList.filter(item => {
          return item.CHLCHAID && item.CHLCHAID.length > 0;
        });
        let data=
        {
          COTCHDID:this.chd.CHDID,
          COTREGID:this.chd.REGID,
          COTBUYNAME:this.chd.REGBUYNAME,
          List_Chl:chlList
        };
        apiBase.DoService(data, apiBase.getApiAdress().Cost.Create, res => {
          this.$message({
            type: "success",
            message: "保存成功!"
          });
          this.closeDialog();
          this.refreshData();
        });
      },
      //新增行
      insert() {
        for (let index in this.chlList) {
          let chl = this.chlList[index];
          if (chl.CHLCHAID.length === 0) {
            this.$message({
              type: "error",
              message: `第${parseInt(index) + 1}行收费项目不能为空!`
            });
            return false;
          }
        }
        this.chlList.push(JSON.parse(JSON.stringify(this.chl)));
        return true;
      },
      remove(index) {
        this.chlList.splice(index, 1);
      },
      //回车事件
      enterEvent(rowNum, colNum) {
        //获取所有行
        let rows = this.$refs.inputs.getElementsByClassName("allRow");
        //获取当前行
        let currow = rows[rowNum];
        // 获取当前行所有列
        let inputs = currow.getElementsByTagName("input");
        //强制隐藏下拉框
        if (colNum === 0) {
          let chl = this.chlList[rowNum];
          if (chl.CHLCHAID.length === 0) {
            this.$message({
              type: "error",
              message: `第${parseInt(rowNum) + 1}行收费项目不能为空!`
            });
            return;
          }
          let select = this.$refs.select;
          select[rowNum].visible = false;
        }
        //最后一列
        if (colNum === inputs.length - 1) {
          //最后一行
          if (rowNum === this.chlList.length - 1) {
            //插入空行
            if (!this.insert()) {
              return;
            }
          }
          //换行
          this.$nextTick(function () {
            this.enterEvent(rowNum + 1, -1);
          });
        } else {
          //获取下一个焦点
          this.$nextTick(function () {
            inputs[colNum + 1].select();
          });
        }
      },
      //禁用已选项
      disabled(chaID) {
        let retVal = this.chlList.some(item => {
          return item.CHLCHAID === chaID;
        });
        return retVal;
      },
      //打开弹出框
      open(order, id) {
        this.getParam();
        Object.assign(this.$data, this.$options.data());
        this.COTID = id;
        this.order = order;
        switch (this.order) {
          case ORDER.ADD:
            this.isAdd=true;
            this.title = "费用新增";
            this.chlList = [];
            this.getAllCharge();
            this.$refs.dialog.open();
            break;
           case ORDER.MODIFY:
            this.title = "费用修改";
            this.chlList = [];
            this.dataInfo();
            this.getAllCharge();
            this.insert();
            this.$refs.dialog.open();
            break;
          case ORDER.INFO:
            this.title = "费用详情";
            this.dataInfo();
            this.$refs.info.open();
            break;
          default:
            break;
        }
      },
      //选择收费项目
      chaSelect(index) {
        let chl = this.chlList[index];
        let cha = this.getChaByID(chl.CHLCHAID);
        //初始化chl
        if (cha) {
          chl.CHLCHANAME = cha.CHANAME;
          chl.CHLAUNIT = cha.CHAAUNIT;
          chl.CHLMONEY = cha.CHAMONEY;
          chl.CHLNUM = 1;
          chl.CHLMOUNT = chl.CHLMONEY * chl.CHLNUM;
          chl.CHLREDUCTION = cha.CHAJMMONEY * chl.CHLNUM;
          chl.CHLDISCOUNT = cha.CHADISCOUNT * chl.CHLNUM;
          chl.CHLRECEIVED = chl.CHLMOUNT - chl.CHLREDUCTION - chl.CHLDISCOUNT;
        }
      },
      reset() {
        this.chaList = JSON.parse(JSON.stringify(this.allCharge));
      },
      //获取常用项
      getCommonItem() {
        let data = {};
        apiBase.DoService(data, apiBase.getApiAdress().CommonItem.Query, res => {
          let common = res.data.content.OutData;
          common.forEach(item => {
            var isContain = this.chlList.some(chl => {
              return item.CNOCHAID === chl.CHLCHAID;
            });
            if (!isContain) {
              let chl = JSON.parse(JSON.stringify(this.chl));
              let cha = this.getChaByID(item.CNOCHAID);
              console.log("cha", cha);
              if (cha) {
                chl.CHLCHAID = cha.CHAID;
                chl.CHLCHANAME = cha.CHANAME;
                chl.CHLAUNIT = cha.CHAAUNIT;
                chl.CHLMONEY = cha.CHAMONEY;
                chl.CHLNUM = 1;
                chl.CHLMOUNT = chl.CHLMONEY * chl.CHLNUM;
                chl.CHLREDUCTION = cha.CHAJMMONEY * chl.CHLNUM;
                chl.CHLDISCOUNT = cha.CHADISCOUNT * chl.CHLNUM;
                chl.CHLRECEIVED =
                  chl.CHLMOUNT - chl.CHLREDUCTION - chl.CHLDISCOUNT;
              }
              this.chlList.push(chl);
            }
          });
          this.chlList = this.chlList.filter(item => {
            return item.CHLCHAID && item.CHLCHAID.length > 0;
          });
          this.chlList.push(JSON.parse(JSON.stringify(this.chl)));
        });
      },
      //ID获取收费项目
      getChaByID(chaId) {
        for (var i in this.allCharge) {
          var cha = this.allCharge[i];
          if (cha.CHAID === chaId) {
            return cha;
          }
        }
      },
      check(index) {
        let chl = this.chlList[index];
        chl.CHLMONEY = this.checkMoney(chl.CHLMONEY.toString());
        chl.CHLNUM = this.checkNumber(chl.CHLNUM.toString());
        chl.CHLDISCOUNT = this.checkMoney(chl.CHLDISCOUNT.toString());
      },
      isCommon() {
        return this.order === ORDER.CHEMODIFY;
      },
      //只能输入正整数
      checkNumber(value) {
        value = value.replace(/\D/g, "").replace(/^0+(?=\d)/, "");
        if (value !== "") {
          if (value.substr(0, 1) === "0" && value.length === 2) {
            value = value.substr(1, value.length);
          }
        } else {
          value = 0;
        }
        return value;
      },
      //只能输入金额
      checkMoney(value) {
        //修复第一个字符是小数点 的情况.
        if (value !== "" && value.substr(0, 1) === ".") {
          value = "";
        }
        value = value.replace(/^0*(0\.|[1-9])/, "$1"); //解决 粘贴不生效
        value = value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
        value = value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
        value = value
          .replace(".", "$#$")
          .replace(/\./g, "")
          .replace("$#$", ".");
        value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
        if (value.indexOf(".") < 0 && value !== "") {
          //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
          if (value.substr(0, 1) === "0" && value.length === 2) {
            value = value.substr(1, value.length);
          }
        } else if (value === "") {
          value = 0;
        }
        return value;
      },
      //计算当前行CHL
      chlCompute(index) {
        let chl = this.chlList[index];
        let cha = this.getChaByID(chl.CHLCHAID);
        if (cha) {
          chl.CHLMOUNT = chl.CHLMONEY * chl.CHLNUM;
          chl.CHLREDUCTION = cha.CHAJMMONEY * chl.CHLNUM;
          chl.CHLRECEIVED = chl.CHLMOUNT - chl.CHLREDUCTION - chl.CHLDISCOUNT;
        }
      },
      //自定义筛选
      chaFilter(val) {
        this.chaList = JSON.parse(JSON.stringify(this.allCharge));
        if (val) {
          if (val.length > 0)
            this.chaList = this.allCharge.filter(item => {
              return (
                item.CHANAME.indexOf(val) > -1 ||
                item.CHADM.toLowerCase().indexOf(val.toLowerCase()) > -1
              );
            });
        }
      },
      //提交
      submit() {
        switch (this.order) {
          case ORDER.ADD:
            this.dataAdd();
            break;
          case ORDER.MODIFY:
            this.dataModify();
            break;
          default:
            break;
        }
      },
      closeDialog() {
        switch (this.order) {
          case ORDER.ADD:
          case ORDER.MODIFY:
            this.$refs.dialog.close();
            break;
          case ORDER.INFO:
            this.$refs.info.close();
            break;
          default:
            break;
        }
      },
      refreshData() {
        this.$emit("refreshData");
      },
    },
    computed: {
      mountTotal() {
        let total = 0;
        for (let chl of this.chlList) {
          total = accAdd(total, chl.CHLMOUNT);
        }
        return total;
      },
      reductionTotal() {
        let total = 0;
        for (let chl of this.chlList) {
          total = accAdd(total, chl.CHLREDUCTION);
        }
        return total;
      },
      discountTotal() {
        let total = 0;
        for (let chl of this.chlList) {
          total = accAdd(total, chl.CHLDISCOUNT);
        }
        return total;
      },
      chlreceivedTotal() {
        let total = 0;
        for (let chl of this.chlList) {
          total = accAdd(total, chl.CHLRECEIVED);
        }
        return total;
      },
      isAdd() {
        return this.order === ORDER.ADD || this.order === ORDER.RETMODIFY;
      }
    },
    watch: {
      chlList: {
        handler(newValue, oldValue) {
          for (let chl of this.chlList) {
            let cha = this.getChaByID(chl.CHLCHAID);
            if (cha) {
              //减免单价大于单价，减免单价取单价
              var CHAJMMONEY = cha.CHAJMMONEY;
              if (chl.CHLMONEY < cha.CHAJMMONEY) {
                CHAJMMONEY = chl.CHLMONEY;
              }
              chl.CHLMOUNT = accMul(chl.CHLMONEY, chl.CHLNUM);
              //减免金额大于减免限价，减免金额取限价
              var CHLREDUCTION = accMul(CHAJMMONEY, chl.CHLNUM);
              if (cha.CHAJMHIMONEY !== 0 && CHLREDUCTION > cha.CHAJMHIMONEY) {
                chl.CHLREDUCTION = cha.CHAJMHIMONEY;
              } else {
                chl.CHLREDUCTION = CHLREDUCTION;
              }
              //优惠金额不能大于优惠限价
              var CHLJMH = Subtr(chl.CHLMOUNT, chl.CHLREDUCTION);
              var CHAHIDISCOUNT = cha.CHAHIDISCOUNT;
              if (cha.CHAHIDISCOUNT !== 0) {
                if (cha.CHAHIDISCOUNT > CHLJMH) {
                  CHAHIDISCOUNT = CHLJMH;
                }
              } else {
                CHAHIDISCOUNT = CHLJMH;
              }
              if (chl.CHLDISCOUNT > CHAHIDISCOUNT) {
                chl.CHLDISCOUNT = CHAHIDISCOUNT;
              }
              chl.CHLRECEIVED = Subtr(CHLJMH, chl.CHLDISCOUNT);
            }
          }
        },
        deep: true
      }
    },
    components: {
      sweetModal
    }
  };

</script>